from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=False)
import pandas as pd
import numpy as np
import plotly.express as px
import matplotlib.pyplot as plt
print('modules are imported')
modules are imported
dataset_url = 'https://raw.githubusercontent.com/datasets/covid-19/main/data/countries-aggregated.csv'
fname = 'data/countries-aggregated.csv'
df = pd.read_csv(fname)
df_31May21 = df[df.Date == '2020-05-31']
df_31May21.head()
| Date | Country | Confirmed | Recovered | Deaths | |
|---|---|---|---|---|---|
| 130 | 2020-05-31 | Afghanistan | 15208 | 1328 | 258 |
| 658 | 2020-05-31 | Albania | 1137 | 872 | 33 |
| 1186 | 2020-05-31 | Algeria | 9394 | 5748 | 653 |
| 1714 | 2020-05-31 | Andorra | 764 | 694 | 51 |
| 2242 | 2020-05-31 | Angola | 86 | 18 | 4 |
df_31May21.head()
| Date | Country | Confirmed | Recovered | Deaths | |
|---|---|---|---|---|---|
| 130 | 2020-05-31 | Afghanistan | 15208 | 1328 | 258 |
| 658 | 2020-05-31 | Albania | 1137 | 872 | 33 |
| 1186 | 2020-05-31 | Algeria | 9394 | 5748 | 653 |
| 1714 | 2020-05-31 | Andorra | 764 | 694 | 51 |
| 2242 | 2020-05-31 | Angola | 86 | 18 | 4 |
df_31May21.tail()
| Date | Country | Confirmed | Recovered | Deaths | |
|---|---|---|---|---|---|
| 100450 | 2020-05-31 | Vietnam | 328 | 279 | 0 |
| 100978 | 2020-05-31 | West Bank and Gaza | 448 | 372 | 3 |
| 101506 | 2020-05-31 | Yemen | 323 | 14 | 80 |
| 102034 | 2020-05-31 | Zambia | 1057 | 779 | 7 |
| 102562 | 2020-05-31 | Zimbabwe | 178 | 29 | 4 |
df_31May21.shape
(195, 5)
df.shape
(102960, 5)
dfconf=df[df.Confirmed>0]
dfconf.head()
| Date | Country | Confirmed | Recovered | Deaths | |
|---|---|---|---|---|---|
| 33 | 2020-02-24 | Afghanistan | 1 | 0 | 0 |
| 34 | 2020-02-25 | Afghanistan | 1 | 0 | 0 |
| 35 | 2020-02-26 | Afghanistan | 1 | 0 | 0 |
| 36 | 2020-02-27 | Afghanistan | 1 | 0 | 0 |
| 37 | 2020-02-28 | Afghanistan | 1 | 0 | 0 |
dfconf.shape
(91970, 5)
dfconf[dfconf.Country=='Italy'].head(10)
| Date | Country | Confirmed | Recovered | Deaths | |
|---|---|---|---|---|---|
| 44889 | 2020-01-31 | Italy | 2 | 0 | 0 |
| 44890 | 2020-02-01 | Italy | 2 | 0 | 0 |
| 44891 | 2020-02-02 | Italy | 2 | 0 | 0 |
| 44892 | 2020-02-03 | Italy | 2 | 0 | 0 |
| 44893 | 2020-02-04 | Italy | 2 | 0 | 0 |
| 44894 | 2020-02-05 | Italy | 2 | 0 | 0 |
| 44895 | 2020-02-06 | Italy | 2 | 0 | 0 |
| 44896 | 2020-02-07 | Italy | 3 | 0 | 0 |
| 44897 | 2020-02-08 | Italy | 3 | 0 | 0 |
| 44898 | 2020-02-09 | Italy | 3 | 0 | 0 |
fig = px.choropleth(dfconf, locations='Country', locationmode='country names', color='Confirmed', animation_frame='Date')
fig.layout.updatemenus[0].buttons[0].args[1]['frame']['duration'] = 30
fig.layout.updatemenus[0].buttons[0].args[1]['transition']['duration'] = 5
fig.update_geos(projection_type="equirectangular", visible=True, resolution=50)
fig.update_layout(
title_text = 'Global Spread of Coronavirus',
title_x = 0.5,
geo=dict(
showframe = False,
showcoastlines = False,
))
#fig.show()
iplot(fig,show_link=False)